package com.huiquan.section.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.huiquan.framework.base.EnhancedBaseDao;
import com.huiquan.section.domain.SectionSynonymy;
import com.ibatis.sqlmap.client.SqlMapClient;

@Repository
public class SectionSynonymyDao extends EnhancedBaseDao<SectionSynonymy> {

	@Resource(name = "sqlMapClient")
	private SqlMapClient sqlMapClient;
	
	public SqlMapClient getSqlMapClient(){
		return sqlMapClient;
	}
	public static final String space = "SECTION_SYNONYMY.";

	public SectionSynonymyDao() {
		super(space);
	}

	public int retrieveSize(Map<String, Object> param) {
		return (Integer) this.object(space + "RETRIEVE_SIZE", param, sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<SectionSynonymy> retrievesList(Map<String, Object> param) {
		return (List<SectionSynonymy>) this.list(space + "RETRIEVE_LIST", param, sqlMapClient);
	}

	
	
	public void deleteAll() {
		Map<String, Object> param = new HashMap<>();
		update(space + "DELETE_ALL", param, sqlMapClient);
	}
	public void batchInsert(List<SectionSynonymy> labelList) {
		int start = 0, end, size = labelList.size();
		List<SectionSynonymy> tempList;

		while (start < size) {
			if (start + 2000 < size) {
				end = start + 2000;
			} else {
				end = size;
			}
			tempList = labelList.subList(start, end);
			this.insert(space + "BATCH_INSERT", tempList, sqlMapClient);
			start += 2000;
		}
	}
	@SuppressWarnings("unchecked")
	public List<String> checkKsNameDisable() {
		Map<String, Object> param = new HashMap<>();
		return (List<String>) this.list(space + "CHECK_KS_NAME_DISABLE", param, sqlMapClient);
	}
	public SectionSynonymy retrieveById(Long id) {
		Map<String, Object> param = new HashMap<>();
		param.put("id", id);
		return (SectionSynonymy)this.object(space + "RETRIEVE_BY_ID", param, sqlMapClient);
	}
	public void updateAllBySectionName(Map<String, Object> param) {
		update(space + "UPDATE_ALL_BY_SECTION_NAME", param, sqlMapClient);
	}
	public void updateSectionNameById(Map<String, Object> param) {
		update(space + "UPDATE_SECTION_NAME_BY_ID", param, sqlMapClient);
	}
	
	/**
	 * 根据一个Map自定义获取列表
	 * @param param
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<Map<String, String>> retrieveSectionSynonymyRelatList() {
		return (List<Map<String, String>>) this.list(space + "RETRIEVE_SECTION_SYNONYMY_RELAT",  sqlMapClient);
	}
}
